﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Portal.Web.Global;
using Portal.Db.Service;
using Portal.Core;
using Portal.Utilities;
using Portal.Web.Framework;
using Portal.AssetTn.Model;
using Portal.Ws.Utilities.Ws;
using Portal.Ws.Utilities;
using System.IO;

namespace Portal.Gui.Web.WebParts.AssetTn
{
    public class AssetStatusBll
    {
        public AssetStatusCls[] ReadingAssetStatus(string SiteId, string Keyword)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "ReadingAssetStatus");
            oWsInParam.Keyword=Keyword;
            WsOutParam outParam = UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
            AssetStatusCls[] AssetStatus = AssetStatusParser.ParseMultiRecordFromXml(outParam.XmlData);
            if (AssetStatus == null) AssetStatus = new AssetStatusCls[0];
            return AssetStatus;
        }



        public AssetStatusCls CreateAssetStatusModel(string SiteId, string AssetStatusId)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "CreateAssetStatusModel");
            oWsInParam.KeyId = AssetStatusId;
            WsOutParam outParam = UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
            AssetStatusCls OAssetStatus = AssetStatusParser.ParseFromXml(outParam.XmlData);
            return OAssetStatus;
        }


        public void SaveAssetStatus(string SiteId, string AssetStatusId, AssetStatusCls OAssetStatus)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "SaveAssetStatus");
            oWsInParam.KeyId = AssetStatusId;
            oWsInParam.XmlData = AssetStatusParser.GetXml(OAssetStatus);
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }


        public void AddAssetStatus(string SiteId, AssetStatusCls OAssetStatus)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "AddAssetStatus");
            oWsInParam.XmlData = AssetStatusParser.GetXml(OAssetStatus);
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }


        public void DeleteAssetStatus(string SiteId, string AssetStatusId)
        {
            SiteParam oSiteParam = Environments.CreateSiteParam(SiteId);
            WsInParam oWsInParam = WebServiceUtility.CreateWsInParam(oSiteParam, "Portal.Ws.AssetTn.Bussiness.dll", "DeleteAssetStatus");
            oWsInParam.KeyId = AssetStatusId;
            UtilitiesBll.ProcessCommand(SiteId, oWsInParam);
        }
    }
}
